home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / GMSMTH01.ZIP / MOVESIGN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-08  |  3.7 KB  |  119 lines

  1. /* Rotates and moves polygon-based objects (only balls, at the moment). */
  2. // this is a slightly modified moveobj.c
  3.  
  4. #include <polygon.h>
  5.  
  6. #include "initsign.h"
  7.  
  8. #define X_BALL_MOVE 65536l
  9. #define Y_BALL_MOVE 65536l
  10. #define Z_BALL_MOVE 0x20000l
  11.  
  12. #define FifteenK 9830400000l       //(INT_TO_FIXED(15000))
  13. #define MinusFifteenK -9830400000l //(INT_TO_FIXED(-15000))
  14.  
  15. /* X, Y, Z rotations for balls, in tenths of degrees (angles) */
  16. static RotateControl InitialRotate[] ={ {0,10,0}};
  17.  
  18. // ALWAYS move everything!!! - if you try to save time by clipping here
  19. // you cause a horrid mess!!!
  20.  
  21. void RotateAndMoveSign(PObject * ObjectToMove)
  22. {
  23.    /* Change the spin axis from X to Y or Y to X if requested by the user */
  24.    if (BallEvent & FLIP_SPIN_AXIS) {
  25.       if (ObjectToMove->Rotate.RotateX != 0) {
  26.          ObjectToMove->Rotate.RotateX = 0;
  27.          ObjectToMove->Rotate.RotateY = 25; /* 10 degree Y rotations */
  28.       } else if (ObjectToMove->Rotate.RotateY != 0) {
  29.          ObjectToMove->Rotate.RotateY = 0;
  30.          ObjectToMove->Rotate.RotateZ = 12; /* 5 degree Z rotations */
  31.       } else {
  32.          ObjectToMove->Rotate.RotateZ = 0;
  33.          ObjectToMove->Rotate.RotateX = 64; /* 1.6 degree X rotations */
  34.       }
  35.    }
  36.  
  37.    if (BallEvent & SPIN_X_AXIS)
  38.     {
  39.       ObjectToMove->Rotate = InitialRotate[0];
  40.  
  41.       ObjectToMove->Rotate.RotateX = 25; /* 1.6 degree X rotations */
  42.       ObjectToMove->Rotate.RotateY = 0;
  43.       ObjectToMove->Rotate.RotateZ = 0;
  44.     }
  45.  
  46.    if (BallEvent & SPIN_Y_AXIS)
  47.     {
  48.       ObjectToMove->Rotate = InitialRotate[0];
  49.  
  50.       ObjectToMove->Rotate.RotateX = 0;
  51.       ObjectToMove->Rotate.RotateY = 30; /* 10 degree Y rotations */
  52.       ObjectToMove->Rotate.RotateZ = 0;
  53.     }
  54.  
  55.    if (BallEvent & SPIN_Z_AXIS)
  56.     {
  57.       ObjectToMove->Rotate = InitialRotate[0];
  58.  
  59.       ObjectToMove->Rotate.RotateX = 0;
  60.       ObjectToMove->Rotate.RotateY = 0;
  61.       ObjectToMove->Rotate.RotateZ = 12; /* 5 degree Z rotations */
  62.     }
  63.  
  64.    /* Rotate the ball as needed */
  65.    if (--ObjectToMove->RDelayCount == 0) {   /* rotate */
  66.       ObjectToMove->RDelayCount = ObjectToMove->RDelayCountBase;
  67.       if (ObjectToMove->Rotate.RotateX != 0)
  68.          AppendRotationX(ObjectToMove->XformToWorld,
  69.                ObjectToMove->Rotate.RotateX);
  70.       if (ObjectToMove->Rotate.RotateY != 0)
  71.          AppendRotationY(ObjectToMove->XformToWorld,
  72.                ObjectToMove->Rotate.RotateY);
  73.       if (ObjectToMove->Rotate.RotateZ != 0)
  74.          AppendRotationZ(ObjectToMove->XformToWorld,
  75.                ObjectToMove->Rotate.RotateZ);
  76.       ObjectToMove->RecalcXform = 1;
  77.    }
  78.  
  79.    /* Move the ball in response to recorded key events */
  80.    if (BallEvent & MOVE_LEFT)
  81.       {
  82.       ObjectToMove->XformToWorld[0][3] -= X_BALL_MOVE;
  83.       ObjectToMove->RecalcXform = 1;
  84.       }
  85.    if (BallEvent & MOVE_RIGHT)
  86.       {
  87.       ObjectToMove->XformToWorld[0][3] += X_BALL_MOVE;
  88.       ObjectToMove->RecalcXform = 1;
  89.       }
  90.    if (BallEvent & MOVE_UP)
  91.       {
  92.       ObjectToMove->XformToWorld[1][3] += Y_BALL_MOVE;
  93.       ObjectToMove->RecalcXform = 1;
  94.       }
  95.    if ( BallEvent & MOVE_DOWN)
  96.       {
  97.       ObjectToMove->XformToWorld[1][3] -= Y_BALL_MOVE;
  98.       ObjectToMove->RecalcXform = 1;
  99.       }
  100.    if (BallEvent & MOVE_TOWARD)
  101.       {
  102.       if (ObjectToMove->XformToWorld[2][3] < MIN_Z)
  103.          {
  104.          ObjectToMove->XformToWorld[2][3] += Z_BALL_MOVE;
  105.          ObjectToMove->RecalcXform = 1;
  106.          }
  107.       }
  108.    if (BallEvent & MOVE_AWAY)
  109.       {
  110.       //if (ObjectToMove->XformToWorld[2][3] > MinusFifteenK)
  111.          {
  112.          ObjectToMove->XformToWorld[2][3] -= Z_BALL_MOVE;
  113.          ObjectToMove->RecalcXform = 1;
  114.          }
  115.       }
  116. }
  117.  
  118. 
  119.